local Signal = require"ecs.signal"

local mt = {insId=0}
mt.__index = mt

function mt.New(cls)
    mt.insId = mt.insId + 1
    local self = setmetatable({},cls)
    self.id = mt.insId
    self.removed = false
    self._components = {}
    self.onComponentAdded = Signal:New()
    self.onComponentRemoved = Signal:New()
    return self
end

function mt:hasComponent(name)
    return self._components[name] and true or false
end

function mt:getComponent(name)
    return self._components[name]
end

function mt:addComponent(component)
    self._components[component.name] = component
    self.onComponentAdded:emit(self, component.name)
end

function mt:removeComponent(name)
    self._components[name] = nil
    self.onComponentRemoved:emit(self, component.name)
end

return mt
